package com.matt.domain;

import lombok.Data;
import org.assertj.core.util.Lists;
import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
 * @Describle This Class Is
 * @Author ZengMin
 * @Date 2018/12/20 17:07
 * @Company Matt
 */
@Data
public class TeachingTempleteCourseVo {

    private String id;

    private String fieldName;

    private String parentName;

    private String parentId;

    private Integer childType;

    private String childTypeVal;

    private Boolean multi;

    private String chooseItem;

    private Long sort;

    private Object value;

    private String filedCode;

    public static List<TeachingTempleteCourseVo> of(List<TeachingTempleteDetail> teachingTempleteDetails,String parentId,String parentName){
        List<TeachingTempleteCourseVo> list = Lists.newArrayList();
        teachingTempleteDetails.stream().forEach( o ->{
            TeachingTempleteCourseVo templeteCourseVo = new TeachingTempleteCourseVo();
            templeteCourseVo.setId(o.getId());
            templeteCourseVo.setChildType(o.getChildType());
            templeteCourseVo.setChildTypeVal(o.getChildTypeVal());
            templeteCourseVo.setChooseItem(o.getChooseItem());
            templeteCourseVo.setMulti(o.isMulti());
            templeteCourseVo.setFieldName(o.getName());
            templeteCourseVo.setParentId(parentId);
            templeteCourseVo.setParentName(parentName);
            templeteCourseVo.setSort(o.getSort());
            list.add(templeteCourseVo);
        });
        return list;
    }


    public static TeachingTempleteCourseVo of(Map<String, Object> map) {
        TeachingTempleteCourseVo templeteCourseVo = new TeachingTempleteCourseVo();
        templeteCourseVo.setId(Objects.isNull(map.get("id")) ? null : map.get("id").toString());
        templeteCourseVo.setFieldName(Objects.isNull(map.get("fieldName")) ? null : map.get("fieldName").toString());
        templeteCourseVo.setParentName(Objects.isNull(map.get("parentName")) ? null : map.get("parentName").toString());
        templeteCourseVo.setParentId(Objects.isNull(map.get("parentId")) ? null : map.get("parentId").toString());
        templeteCourseVo.setChildType(Objects.isNull(map.get("childType")) ? null : Integer.parseInt(map.get("childType").toString()));
        templeteCourseVo.setChildTypeVal(Objects.isNull(map.get("childTypeVal")) ? null : map.get("childTypeVal").toString());
        templeteCourseVo.setMulti(Objects.isNull(map.get("multi")) ? null : Boolean.parseBoolean(map.get("multi").toString()));
        templeteCourseVo.setChooseItem(Objects.isNull(map.get("chooseItem")) ? null : map.get("chooseItem").toString());
        templeteCourseVo.setSort(Objects.isNull(map.get("sort")) ? null : Long.valueOf(map.get("sort").toString()));
        templeteCourseVo.setFiledCode(Objects.isNull(map.get("filedCode")) ? null : map.get("filedCode").toString());
        templeteCourseVo.setValue(Objects.isNull(map.get("value")) ? null : map.get("value"));
        return templeteCourseVo;
    }

}
